# Contributor: Alexey Yerin <yyp@disroot.org>
# Maintainer: Alexey Yerin <yyp@disroot.org>
pkgname=wasm-tools
pkgver=1.215.0
_testsuite_commit=53da17c0936a23f68f97cde4f9346a0a374dc35f
pkgrel=0
pkgdesc="CLI for low-level manipulation of WebAssembly modules"
url="https://github.com/bytecodealliance/wasm-tools"
arch="all"
license="Apache-2.0 OR Apache-2.0 WITH LLVM-exception OR MIT"
makedepends="cargo"
subpackages="$pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/bytecodealliance/wasm-tools/archive/refs/tags/v$pkgver.tar.gz
	testsuite-$_testsuite_commit.tar.gz::https://github.com/WebAssembly/testsuite/archive/$_testsuite_commit.tar.gz
	"

prepare() {
	default_prepare

	rm -r tests/testsuite
	cp -r "$srcdir/testsuite-$_testsuite_commit" tests/testsuite

	cargo fetch --target="$CTARGET" --locked
}

build() {
	# Using regular cargo since cargo-auditable crashes while resolving dependencies, likely due to
	# https://github.com/rust-secure-code/cargo-auditable/issues/66
	cargo build --frozen --release --bin wasm-tools
}

check() {
	cargo test --frozen
}

package() {
	install -Dm755 target/release/wasm-tools "$pkgdir"/usr/bin/wasm-tools

	for license in LICENSE-APACHE LICENSE-Apache-2.0_WITH_LLVM-exception LICENSE-MIT; do
		install -Dm644 $license "$pkgdir"/usr/share/licenses/wasm-tools/$license
	done
}

sha512sums="
fffe42917db550ab74a47137d94e9e27106fba5aca71e4d2258025fbbf5ec411d94cef4efd1af1220f4d7427d187f4eedf6512ee35abac58515eb2f9b8dc7e75  wasm-tools-1.215.0.tar.gz
e2a885d2428b64e35d6dcf9cbbd90ae50528911400579b19482e16b0eaa39250cb8fafca9e9faed220a7e222a5b8d0033e4c8aebc58868512d5f0822d3ab1dfc  testsuite-53da17c0936a23f68f97cde4f9346a0a374dc35f.tar.gz
"
